import 'package:hrf_app/common/extension/ex_visibility.dart';
import 'package:hrf_app/common/index.dart';
import 'package:hrf_app/common/models/bug/project_bug_model.dart';
import 'package:hrf_app/common/models/bug/project_model.dart';
import 'package:hrf_app/common/services/user.dart';
import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

import 'index.dart';

class ProjectListPage extends GetView<ProjectListPageController> {
  const ProjectListPage({super.key});

  Widget _buildView() {
    List<ProjectModel> projectList = controller.projectList;
    return Column(
      children: [
        Expanded(
            child: EasyRefresh(
          controller: controller.easyRefreshController,
          onRefresh: () async {
            print("下拉刷新逻辑");
            controller.onRefresh();
          },
          onLoad: () async {
            print("上拉加载逻辑");
            controller.onLoad();
          },
          child: ListView.builder(
              itemCount: projectList.length,
              itemBuilder: (context, index) {
                ProjectModel projectBugModel = projectList[index];
                return _buildItemView(projectBugModel);
              }),
        ))
      ],
    );
  }

  // 主视图
  Widget _buildItemView(ProjectModel projectModel) {
    return Container(
        margin: const EdgeInsets.all(8),
        padding: const EdgeInsets.all(8),
        decoration: BoxDecoration(
          color: Colors.white,
          boxShadow: const [BoxShadow(color: Colors.grey, blurRadius: 0.3)],
          borderRadius: BorderRadius.circular(10),
        ),
        child: SizedBox(height: 80, child: _buildBugInfo(projectModel)));
  }

  Widget _buildBugInfo(ProjectModel projectBugModel) {
    List<Widget> columList = [];
    columList.add(buildInfoDetailTitle("项目：", projectBugModel.name!));
    columList.add(buildInfoDetailIDLeftRight(
        Row(
          children: [
            itemTitle(
              "创建人：",
            ),
            TDText(projectBugModel.creatorName??""),
          ],
        ),
        Row(
        )));

    columList.add(
      buildInfoDetailTitle(
        "创建时间：",
        projectBugModel.createTime!,
      ),
    );
    return InkWell(
        onTap: () {
          controller.onJumpToDetail(projectBugModel.id);
        },
        child: Column(children: columList));
  }

//标题内容行
  Widget buildInfoDetailTitle(String title, String content) {
    return Row(
      children: [
        TDText(
          title,
          fontWeight: FontWeight.w700,
        ),
        Expanded(
          child: TDText(
            content,
            overflow: TextOverflow.ellipsis,
          ),
        )
      ],
    );
  }

//标题

  Widget buildInfoDetailIDLeftRight(Widget leftWidget, Widget rightWidget) {
    return Row(
      children: [
        Expanded(flex: 3, child: leftWidget),
        Expanded(flex: 3, child: rightWidget),
      ],
    );
  }

  Widget itemTitle(title) {
    return TDText(
      title,
      fontWeight: FontWeight.w700,
    );
  }

  @override
  Widget build(BuildContext context) {
    return GetBuilder<ProjectListPageController>(
      init: ProjectListPageController(),
      id: "projectPage",
      builder: (_) {
        return Scaffold(
          appBar: AppBar(
            title: const Text(
              "项目管理",
            ),
          ),
          floatingActionButton: FloatingActionButton(
            onPressed: () {
          controller.   jumpToProjectAdd();
            },
            tooltip: '增加',
            shape: CircleBorder(),
            child: Icon(Icons.add),
          ),
          body: SafeArea(
            child: _buildView(),
          ),
        );
      },
    );
  }
}
